package springIOC.IOC_XML.handler;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

public class BeanResultSetHandler<T> implements ResultSetHandler<T> {

    Class<T> classMap;

    public BeanResultSetHandler(Class<T> clazz){
        this.classMap=clazz;
    }


    @Override
    public T handle(ResultSet resultSet) throws SQLException {
        resultSet.next();
        if(!resultSet.isLast()){
            System.out.println("结果集大于1条，无法匹配");
            return null;
        }
//        Type t;
//        Class<T> tClass=(Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];

        return new ResultSetUtil().resultSetToBean(classMap,resultSet);
    }
}
